<template>
  <div class="info_page">
    <div class="base_info">
      <a-avatar :src="photo" :size="120" />
      <span class="name">{{name}}</span>
      <div class="com_box">
        <span>{{company}}</span>
        <span>{{apartment}}</span>
        <span>{{business}}</span>
        <span>{{level}}</span>
      </div>
      <div class="contact_box">
        <span><a-icon type="phone" class="margin4-right" />{{phone}}</span>
        <span><a-icon type="mail" class="margin4-right" />{{email}}</span>
      </div>
      <div>
        <a-tag color="blue">{{type}}</a-tag>
        <a-icon :type="gender===1?'man':'woman'" :class="gender===1?'blue-color':'red-color'" />
      </div>
    </div>
    <div class="detail_box">
      <ul class="info_ul">
        <li v-for="pane in tabPanes" :key="pane.to" :class="pane.to === activeKey ? 'active' : ''"><NuxtLink :to="pane.to">{{pane.title}}</NuxtLink></li>
      </ul>
      <div class="info_ctn">
        <Nuxt />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  async asyncData({app}) {
    const { result } = await app.$axios.get('/api/info/base')
    return result
  },
  /* 服务端钩子 */
  middleware() {
    console.log('定义在页面内部的middleware, 在这个页面被加载时运行在这个页面被实例化之前')
  },
  /* 参数校验 */
  validate() {
    console.log('validate 返回 true 表示可以访问')
    return true
  },
  /* 服务端和客户端都会触发的钩子 */
  beforeCreate() {
    console.log('beforeCreate')
  },
  /* 服务端和客户端都会触发的钩子 */
  created() {
    console.log('created')
  },
  data() {
    return {
      tabPanes: [
        {title: '个人信息', to: '/info/me'},
        {title: '合同信息', to: '/info/contract'},
        {title: '教育经历', to: '/info/education'},
        {title: '家庭信息', to: '/info/family'},
        {title: '学历学位证上传', to: '/info/file'},
        {title: '职业资格证书', to: '/info/qualification'},
        {title: '入职前工作经历', to: '/info/experience'},
        {title: '培训经历', to: '/info/train'}
      ]
    }
  },
  computed: {
    activeKey: function() {
      return this.$route.fullPath
    }
  }
}
</script>

<style lang="less" scoped>
@ulW: 180px;
.info_page{
  .base_info{
    background-color: #fff;
    margin-bottom: 16px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .name{
      color: #333;
      font-size: 20px;
      font-weight: bold;
      margin: 4px 0;
    }
    .com_box{
      margin-bottom: 4px;
      & > span{
        &:not(:last-child){
          margin-right: 20px;
          position: relative;
          &::after{
            position: absolute;
            content: '';
            width: 1px;
            height: 14px;
            background-color: #d5d5d5;
            top: 3px;
            right: -13px;
          }
        }
      }
    }
    .contact_box{
      margin-bottom: 6px;
      & > span{
        &:not(:last-child){
          margin-right: 24px;
        }
      }
    }
  }
  .detail_box{
    display: flex;
    .info_ul{
      min-width: @ulW;
      width: @ulW;
      list-style: none;
      background-color: #fff;
      margin-right: 16px;
      padding: 16px 0 16px 16px;
      .nuxt-link-active{
        color: @primary-color;
      }
      li{
        padding: 8px 24px;
        text-align: center;
        position: relative;
        &:not(:first-child){
          margin-top: 16px;
        }
        a{
          color: #333;
        }
        &.active::after{
          content: '';
          position: absolute;
          width: 2px;
          height: 37px;
          right: 0;
          top: 0;
          background-color: @primary-color;
        }
      }
    }
    .info_ctn{
      flex-grow: 1;
      background-color: #fff;
      padding: 16px 16px 16px 24px;
    }
  }
}
</style>
